import java.util.ArrayList;
import java.util.List;

public class Library {
    private List<Book> booklist;

    public List<Book> getBooklist() {
        return booklist;
    }

    public void setBooklist(List<Book> booklist) {
        this.booklist = booklist;
    }

    /**
     * 添加图书
     *
     * @param book
     */
    public void addBook(Book book) {
      List<Book> list=  this.getBooklist();
      if(list==null||list.isEmpty()){
          List<Book> createlist=new ArrayList<>();
          createlist.add(book);
          this.setBooklist(createlist);
      }else{
          list.add(book);
      }

    }

    /**
     * 查找图书
     */

    public List<Book> findBookByTitle(String title) {
        List<Book> list = this.getBooklist();
        List<Book> result = new ArrayList<>();
        for (Book book : list) {
            if (book.getTitle().equals(title)) {
                result.add(book);
            }
        }
        return result;
    }

    /**
     * 打印所有图书的借阅状态
     */

    public void showBookStatus() {
        List<Book> list = this.getBooklist();
        for (Book book : list) {
            String isBorrowed = book.getIsBorrowed() ? "已借出" : "未借出";
            System.out.println(book.getTitle() + " 的借阅状态为: " +isBorrowed);

        }
    }

}
